package com.huxi.lang.exception;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * 异常原因消息管理器
 * 
 * @since 1.0
 * @version 1.0
 * @author jian.wu
 *
 */
public class CauseManager {
	
	protected static final int rowNoneIndex = -1;
	protected static final int rowFirstIndex = 0;
	protected static final int columnNoneIndex = -1;
	protected static final int columnFirstIndex = 0;

	private static final String localeKey = "lang.CauseMessageManager.locale";
	public static final String resourceKey = "lang.CauseMessageManager.resource";

	public static Locale locale = null;

	public static Locale getLocale() {
		if (locale == null) {
			synchronized (localeKey) {
				if (locale == null) {
					String name = System.getProperty(localeKey, "");
					if (!name.isEmpty()) {
						// TODO
					}
					if (locale == null) {
						locale = Locale.getDefault();
					}
				}
			}
		}
		return locale;
	}

	public static String getMessage(String pattern) {
		return null;
	}

	public static String format(String pattern, Object... args) {
		return String.format(getLocale(), pattern, args);
	}

	public static String format(Class<?> source, String pattern, Object... args) {
		return pattern;
	}

	public static List<Throwable> mergeMultipleCause(Throwable... causes) {
		ArrayList<Throwable> list = new ArrayList<>();
		if (causes != null) {
			for (Throwable th : causes) {
				if (th instanceof MultipleCause) {
					MultipleCause mcause = (MultipleCause) th;
					list.addAll(mcause.getMultipleCauses());
				} else if (th != null) {
					list.add(th);
				}
			}
		}
		return list;
	}
}
